<!DOCTYPE html>
<uieip type="page" value="login" debug="true" timeout="5000"></uieip>
<uieip type="reg" value="console,model"></uieip>
<html>

<head>
    <uieip type="file" value="inc" src="/yqwin/easyui/include.txt" minute="1440"></uieip>
    <uieip type="file" value="css" src="/yqwin/css/yqwin.min"></uieip>
    <uieip type="file" value="js" src="/yqwin/src/yqwin.min"></uieip>
    <script src="/yqwin/src/yq.flowview.js"></script>
    <uieip type="tmpl" value="model.title"></uieip>
</head>

<body>
    <table id="tb" style="width:100%;height: 350px;"></table>
    <script>
        <uieip type="tmpl" value="model.params"></uieip>
        $(function () {
            main_fun.init();
        });

        var page_fun = {
            init: function () {
                $(window).resize(function () {
                    page_fun.onresize();
                });
                page_fun.onresize();

                main_fun.seek();
            },
            onresize: function () {
                var w = window.innerWidth;
                var h = window.innerHeight;

                if (w < 100) {
                    w = 100;
                }
                if (h < 100) {
                    h = 100;
                }

                main_fun.resize({
                    width: w,
                    height: h
                });
            }
        }

        var main_fun = {
            id: "tb",
            init: function () {
                var opts = $.extend(_tb, {
                    add: false,
                    del: false,
                    linkField: ["topic"],

                    editTitle: "编辑",
                    editMode: 4,
                    editMaximiz: true,
                    editUrl: null,     //编辑url

                    loadData: false,
                    afterBindingTitle: function () {
                        page_fun.init();
                    },
                    onBeforeShowEdit: function (titles, action, row, callback) {      //add/upp/move 编辑执行前
                        var _opts = this.yqDataGrid("options");
                        console.log(action, row);
                        if (action == "upp") {
                            main_fun.get_init_row(row, function (res) {
                                //console.log(res);
                                if (res.error == 0) {
                                    _opts.$row = res.row;
                                    _opts.$type = "wfcomp";
                                    _opts.editUrl = "/adp/test/model_wftest_edit.html?appno=0&menuno=999";
                                    callback(true, titles, row);
                                } else {
                                    $.yqMessager("error", res.info + "[" + res.error + "]");
                                    callback(false, titles, row);
                                }
                            });
                        } else {
                            callback(true, titles, row);
                        }
                    },
                });
                $("#" + main_fun.id).yqDataGrid(opts);
            },
            resize: function (size) {
                $("#" + main_fun.id).yqDataGrid("resize", size);
            },
            seek: function (where) {
                if (where === undefined) {
                    where = "";
                }
                $("#" + main_fun.id).yqDataGrid("seek", where);
            },
            get_init_row: function (row, callback) {
                $_yqFlow.wfInfo(row["pid"], function (res) {
                    if (res.error == 0) {
                        $.yqDbTbRow({
                            dbname: res.row.db_name,
                            tbname: res.row.tb_name,
                            keyid: "sid",
                            keyval: res.row.tb_id
                        }, function (res2) {
                            callback(res2);
                        });
                    } else {
                        callback(res);
                    }
                });
            },
        }

    </script>
</body>

</html>